package by.airlanterns.web;

import by.airlanterns.service.ContentPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: Sergey
 * Date: 03.02.13
 * Time: 13:30
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("info")
public class ContentPageController extends BaseController {

    @Autowired
    private ContentPageService contentPageService;
    private Map<String, Object> model;


    private final static int HOW_TO_USE_INDEX = 1;
    private final static int CONTACTS_INDEX = 2;
    private final static int WHATS_NEW_INDEX = 3;
    private final static int ABOUT_INDEX = 4;


    @RequestMapping(value = "about", method = RequestMethod.GET)
    private ModelAndView showAbout(HttpServletRequest request, HttpServletResponse response) {
        model = getModel();
        model.put("content", contentPageService.getContentByPageId(ABOUT_INDEX));
        model.put("title", "О Нас");
        model.put("index", "" + ABOUT_INDEX);
        return new ModelAndView("info_page", model);
    }

    @RequestMapping(value = "how_to_use", method = RequestMethod.GET)
    private ModelAndView showHowToUse(HttpServletRequest request, HttpServletResponse response) {
        model = getModel();
        model.put("content", contentPageService.getContentByPageId(HOW_TO_USE_INDEX));
        model.put("title", "Правила использования");
        model.put("index", "" + HOW_TO_USE_INDEX);
        return new ModelAndView("info_page", model);
    }

    @RequestMapping(value = "contacts", method = RequestMethod.GET)
    private ModelAndView showContacts(HttpServletRequest request, HttpServletResponse response) {
        model = getModel();
        model.put("content", contentPageService.getContentByPageId(CONTACTS_INDEX));
        model.put("title", "Контакты");
        model.put("index", "" + CONTACTS_INDEX);
        return new ModelAndView("info_page", model);
    }

    @RequestMapping(value = "whats_new", method = RequestMethod.GET)
    private ModelAndView showWhatsNew(HttpServletRequest request, HttpServletResponse response) {
        model = getModel();
        model.put("content", contentPageService.getContentByPageId(WHATS_NEW_INDEX));
        model.put("title", "Что нового");
        model.put("index", "" + WHATS_NEW_INDEX);
        return new ModelAndView("info_page", model);
    }
}
